//
//  ActivityTableViewCell.m
//  ZiJinLian
//
//  Created by 震霄 张 on 2018/3/29.
//  Copyright © 2018年 lzy. All rights reserved.
//

#import "ActivityTableViewCell.h"
#import "JYPicContainerView.h"

@interface ActivityTableViewCell()
@property (nonatomic,weak)UIView *infoView;
@property (nonatomic,weak)UILabel *contentLabel;
@property (nonatomic,weak)UIImageView *headView;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UILabel *desLabel;
@property (nonatomic, weak) JYPicContainerView *picContainerView;
@property (nonatomic,weak)UILabel *startLabel;
@property (nonatomic,weak)UILabel *joinLabel;

@end
@implementation ActivityTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
	if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
		
		[self initUI];
//		[self setupLayout];
	}
	return self;
}
-(void)initUI
{
	UIView *infoView = [[UIView alloc]init];
	[self.contentView addSubview:infoView];
	self.infoView = infoView;
	
	UIImageView *headView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"me_head_nor"]];
	[infoView addSubview:headView];
	self.headView = headView;
	
	UILabel *titleLabel = [[UILabel alloc]init];
	titleLabel.font = [UIFont systemFontOfSize:13];
	titleLabel.textColor = TextColor3;
	titleLabel.text = @"峨眉山白龙寺";
	[self.infoView addSubview: titleLabel];
	self.titleLabel = titleLabel;
	
	UILabel *desLabel = [[UILabel alloc]init];
	desLabel.font = [UIFont systemFontOfSize:11];
	desLabel.textColor = TextColor6;
	desLabel.text = @"湖北省天门市五华山";
	[self.infoView addSubview:desLabel];
	self.desLabel = desLabel;
	
	UILabel *contentLabel = [[UILabel alloc]init];
	contentLabel.font = [UIFont systemFontOfSize:13];
	contentLabel.numberOfLines = 0;
	[self.contentView addSubview:contentLabel];
	contentLabel.text = @"";
	self.contentLabel = contentLabel;
	
	[self.contentView addSubview:self.picContainerView];
	
	UILabel *startLabel = [[UILabel alloc]init];
	startLabel.font = [UIFont systemFontOfSize:11];
	startLabel.textColor = TextColor6;
	[self.contentView addSubview:startLabel];
	startLabel.text = @"开始时间";
	self.startLabel = startLabel;
	
	UILabel *joinLabel = [[UILabel alloc]init];
	joinLabel.textColor = TextColor6;
	joinLabel.font = [UIFont systemFontOfSize:11];
	joinLabel.textAlignment = NSTextAlignmentRight;
	[self.contentView addSubview:joinLabel];
	joinLabel.text = @"参加人数888";
	self.joinLabel = joinLabel;
	
	
}
-(JYPicContainerView *)picContainerView
{
	if(_picContainerView == nil) {
		
		JYPicContainerView *picContainerView = [[JYPicContainerView alloc]init];
		
		_picContainerView = picContainerView;
		
		return picContainerView;
		
	}
	
	return _picContainerView;
}
-(void)setupLayout
{
	CGFloat LRpadding = 15;
	CGFloat Hpadding = 10;
	self.infoView.sd_layout
	.topSpaceToView(self.contentView, Hpadding)
	.leftSpaceToView(self.contentView, LRpadding)
	.rightSpaceToView(self.contentView, LRpadding)
	.heightIs(40);
	
	self.headView.sd_layout
	.topSpaceToView(self.infoView, 0)
	.leftSpaceToView(self.infoView, 0)
	.heightIs(40)
	.widthIs(40);
	
	self.headView.layer.cornerRadius = 20;
	self.headView.clipsToBounds = YES;
	
	self.titleLabel.sd_layout
	.topEqualToView(self.headView)
	.leftSpaceToView(self.headView, 10)
	.rightSpaceToView(self.infoView, 15)
	.heightIs(25);
	
	self.desLabel.sd_layout
	.topSpaceToView(self.titleLabel, 0)
	.leftEqualToView(self.titleLabel)
	.rightEqualToView(self.titleLabel)
	.heightIs(15);
	
	
	self.contentLabel.sd_layout
	.leftSpaceToView(self.contentView, LRpadding)
	.rightSpaceToView(self.contentView, LRpadding)
	.topSpaceToView(_infoView, 10)
	.autoHeightRatio(0);
	
	
	NSInteger coutH = self.model.images.count % 3 == 0 ? self.model.images.count / 3 : self.model.images.count / 3+1;
	if (self.model.images.count == 1) {
		self.picContainerView.sd_resetLayout
		.topSpaceToView(self.contentLabel, 12)
		.rightSpaceToView(self.contentView, LRpadding)
		.leftEqualToView(self.contentLabel)
		.heightIs((screen_Width-LRpadding*2)/16*9);//
	}else{
		self.picContainerView.sd_resetLayout
		.topSpaceToView(self.contentLabel, 12)
		.rightSpaceToView(self.contentView, LRpadding)
		.leftEqualToView(self.contentLabel)
		.heightIs(itemHeight*coutH);//
	}
	


	self.joinLabel.sd_layout
	.topSpaceToView(self.picContainerView, 12)
	.rightEqualToView(self.contentLabel)
	.widthIs(100)
	.heightIs(30);
	
	self.startLabel.sd_layout
	.leftEqualToView(self.contentLabel)
	.topSpaceToView(self.picContainerView, 12)
	.rightSpaceToView(self.joinLabel, 5)
	.heightIs(30);
	
	
	[self setupAutoHeightWithBottomView:self.startLabel bottomMargin:20];
	
}
-(void)setModel:(ActivityModel *)model
{
	_model = model;
	
	self.picContainerView.photoPathArray = model.images;
	[self.headView sd_setImageWithURL:[NSURL URLWithString:model.sponsorLogo] placeholderImage:[UIImage imageNamed:@"me_head_nor"]];
	self.titleLabel.text =model.sponsorName;
	self.desLabel.text = model.sponsorDes;
	self.contentLabel.text = model.activitydescription;
	self.startLabel.text = [NSString stringWithFormat:@"开始时间: %@",[Utils getTimeFromTimestamp:[model.startTime integerValue]]];
	self.joinLabel.text = [NSString stringWithFormat:@"%ld人参与",model.number];
	
	[self setupLayout];

}

@end
